package com.example.deliveryapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import me.jessyan.autosize.internal.CustomAdapt;

public class GetStartedActivity extends AppCompatActivity implements CustomAdapt{

    private TextView countdownTextView;
    private Button skipButton;
    private Handler handler = new Handler();
    private int seconds = 3; // 倒计时时间

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get_started);

        countdownTextView = findViewById(R.id.countdown_text_view);
        skipButton = findViewById(R.id.skip_button);

        skipButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                skipCountdown();
            }
        });

        startCountdown();


    }

    private void startCountdown() {
        countdownTextView.setText(String.valueOf(seconds));
        handler.postDelayed(countdownRunnable, 1000);
    }

    private Runnable countdownRunnable = new Runnable() {
        @Override
        public void run() {
            if (seconds == 0) {
                goToHomeActivity();
            } else {
                seconds--;
                countdownTextView.setText(String.valueOf(seconds));
                handler.postDelayed(this, 1000); // 每秒更新一次
            }
        }
    };

    private void skipCountdown() {
        handler.removeCallbacks(countdownRunnable); // 移除倒计时
        goToHomeActivity();
    }



    private void goToHomeActivity() {
        Intent intent = new Intent(GetStartedActivity.this, LoginActivity.class);
        startActivity(intent);
        finish(); // 结束当前活动
    }



    @Override
    public boolean isBaseOnWidth() {
        return true;
    }

    @Override
    public float getSizeInDp() {
        return 390;
    }

}